import { Button, Flex, Modal } from "antd";

import { UserOrderDataType } from "@/types/order";

type PassModalProps = {
  data: null | UserOrderDataType | UserOrderDataType[];
  open: boolean;
  loading?: boolean;
  onCancel: () => void;
  onOk: () => void;
};

export default function PassModal({ data, open, loading, onCancel, onOk }: PassModalProps) {
  console.log("data: ", data);
  if (!open || !data) return null;

  const records = Array.isArray(data) ? data : [data];
  const isBatch = records.length > 1;
  const isPending = records.some((item) => item.reviewStatus === "rejected");

  const title = isBatch
    ? `是否确定入选【${records.map((item) => item.businessCard.name).join("、")}】？`
    : `是否确定入选【${records[0].businessCard.name}】？`;

  return (
    <>
      <Modal open={open} centered footer={false} onCancel={onCancel}>
        <Flex vertical gap={20} className="pt-4">
          <h1 className="text-base font-bold text-center">
            <span className="w-4/5">{isPending ? "用户未入选，是否修改报名状态为入选？" : title}</span>
          </h1>
          <Flex gap={32} justify="center">
            <Button type="primary" ghost onClick={onCancel} disabled={loading}>
              取消
            </Button>
            <Button type="primary" onClick={onOk} loading={loading}>
              确定
            </Button>
          </Flex>
        </Flex>
      </Modal>
    </>
  );
}
